package Visao;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.text.MaskFormatter;

import Controle.AlunoControle;
import Controle.ControleFuncionario;
import Modelo.Aluno;
import Modelo.Funcionario;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;

import javax.swing.JFormattedTextField;
import javax.swing.ImageIcon;

public class Cadastros extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldNome;
	private JFormattedTextField textFieldCPF;
	private JTextField textFieldEmail;
	private JTextField textFieldMatri;
	private JButton btnCadastrarAluno;
	private JTextField textFieldCurso;
	private Aluno aluno;
	private Funcionario funci;
	private AlunoControle controleAluno;
	private ControleFuncionario controleFuncionario;
	private ControleDeTelas telas;

	/**
	 * Launch the application.
	 */
	
	/**
	 * Create the frame.
	 * @throws ParseException 
	 */
	public Cadastros() throws ParseException {
		telas = new ControleDeTelas();
		aluno = new Aluno();
		funci = new Funcionario();
		controleAluno = new AlunoControle();
		controleFuncionario = new ControleFuncionario();
		setTitle("cadastros");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 451, 300);
		setLocationRelativeTo(null);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnInicio = new JMenu("Inicio");
		mnInicio.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				telas.getInicio().setVisible(true);
				dispose();
				
			}
		});
		menuBar.add(mnInicio);
		
		JMenu mnCadastros = new JMenu("Cadastro Aluno");
		menuBar.add(mnCadastros);
		
		JMenu mnBuscas = new JMenu("Buscas");
		mnBuscas.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				telas.getBusca().setVisible(true);
				dispose();
			}
		});
		
		JMenu mnCadastroFuncionario = new JMenu("Cadastro Funcionario");
		mnCadastroFuncionario.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				telas.getCadastroFuncionario().setVisible(true);
				dispose();
				
			}
		});
		menuBar.add(mnCadastroFuncionario);
		menuBar.add(mnBuscas);
		
		JMenu mnVisitantes = new JMenu("Visitante");
		mnVisitantes.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				try {
					telas.getVisitante().setVisible(true);
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				dispose();
			}
		});
		menuBar.add(mnVisitantes);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNMatricula = new JLabel("N\u00BA Matricula");
		lblNMatricula.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblNMatricula.setBounds(192, 90, 83, 14);
		contentPane.add(lblNMatricula);
		
		textFieldNome = new JTextField();
		textFieldNome.setBounds(81, 52, 286, 20);
		contentPane.add(textFieldNome);
		textFieldNome.setColumns(10);
		
		MaskFormatter msk = new MaskFormatter("***.***.***-**");
		
		
		
		textFieldCPF = new JFormattedTextField(msk);
		textFieldCPF.setBounds(81, 87, 106, 20);
		contentPane.add(textFieldCPF);
		textFieldCPF.setColumns(10);
		
		textFieldEmail = new JTextField();
		textFieldEmail.setBounds(81, 120, 286, 20);
		contentPane.add(textFieldEmail);
		textFieldEmail.setColumns(10);
		
		textFieldMatri = new JTextField();
		textFieldMatri.setBounds(276, 87, 91, 20);
		contentPane.add(textFieldMatri);
		textFieldMatri.setColumns(10);
		
		btnCadastrarAluno = new JButton("Cadastrar");
		btnCadastrarAluno.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				aluno.setCpf(textFieldCPF.getText());
				aluno.setCurso(textFieldCurso.getText());
				aluno.setEmail(textFieldEmail.getText());
				aluno.setMatricula(textFieldMatri.getText());
				aluno.setNome(textFieldNome.getText());
				
				try {
					controleAluno.salvar(aluno);
					JOptionPane.showMessageDialog(null, "Aluno cadastrado!!");
					textFieldCPF.setText("");
					textFieldCurso.setText("");
					textFieldMatri.setText("");
					textFieldNome.setText("");
					textFieldEmail.setText("");
				
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
			}
		});
		btnCadastrarAluno.setBounds(276, 205, 91, 23);
		contentPane.add(btnCadastrarAluno);
		
		textFieldCurso = new JTextField();
		textFieldCurso.setBounds(81, 161, 286, 20);
		contentPane.add(textFieldCurso);
		textFieldCurso.setColumns(10);
		
		JPanel panel = new JPanel();
		panel.setBackground(new Color(0, 139, 139, 50));
		panel.setBounds(10, 11, 377, 228);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("CPF\r\n");
		lblNewLabel.setBounds(10, 76, 46, 14);
		panel.add(lblNewLabel);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		JLabel lblNome = new JLabel("Nome");
		lblNome.setBackground(new Color(0, 0, 0));
		lblNome.setBounds(10, 44, 46, 14);
		lblNome.setFont(new Font("Tahoma", Font.BOLD, 11));
		panel.add(lblNome);
		
		
		JLabel lblAluno = new JLabel("ALUNO");
		lblAluno.setBackground(new Color(0, 0, 0));
		lblAluno.setBounds(10, 11, 79, 19);
		panel.add(lblAluno);
		lblAluno.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		
		JLabel lblNewLabel_1 = new JLabel("e-mail");
		lblNewLabel_1.setBounds(10, 111, 62, 14);
		panel.add(lblNewLabel_1);
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		JLabel lblCurso = new JLabel("Curso");
		lblCurso.setBounds(10, 152, 46, 14);
		panel.add(lblCurso);
		lblCurso.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		JLabel lblNewLabel_2 = new JLabel("New label");
		lblNewLabel_2.setIcon(new ImageIcon("H:\\workspace\\SupportWatchful\\Imagens\\i=magem lois.jpg"));
		lblNewLabel_2.setBounds(0, 0, 443, 252);
		contentPane.add(lblNewLabel_2);
	}
}
